package cn.parus.commons.common.Log.service;

import cn.parus.commons.common.Log.dao.Repsitory.LogRepository;
import cn.parus.commons.common.Log.entity.LogInfo;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Title: LogService
 * @Author 潘春兰
 * @Package cn.parus.commons.common.Log.service
 * @Date 2025/4/2 22:54
 * @description: TODO 日志服务类
 * @Version:
 */
@Service
public class LogService {
    private final LogRepository logRepository;
    /**
     * TODO 构造函数, 注入 LogRepository避免循环依赖
     * @param LogRepository
     */
    public LogService(LogRepository LogRepository) {
        this.logRepository = LogRepository;
    }

    /**
     * 获取日志列表
     * @param pageNum
     * @param pageSize
     * @return
     */

    public Page<LogInfo> getLogs(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        System.out.println("Service参数======" + pageNum + pageSize);
        PageRequest pageRequest = PageRequest.of(pageNum - 1, pageSize);
        return logRepository.findAll(pageRequest);
    }
    /**
     * 根据id删除日志
     */
    public void deleteLogById(Long logId) {
        logRepository.deleteById(logId);
    }

    /**
     * 批量删除日志
     */
    public void deleteLogsByIds(List<Long> logIds) {
        logRepository.deleteAllById(logIds);
    }
}
